﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HFController;
using System.Web.Script.Serialization;

namespace HFWebApp.AjaxSource
{
    /// <summary>
    /// NewsSource 的摘要说明
    /// </summary>
    public class NewsSource : IHttpHandler
    {
        public List<hf.Model.News> newsList = new List<hf.Model.News>();
        public void ProcessRequest(HttpContext context)
        {
            BagePages bp = new BagePages();
            string classid = bp.GetQuery("classid");
            string strSql = "bClassID=" + classid;

            newsList = NewsController.getController().getNewsListForAjax(8, strSql);

            context.Response.ContentType = "text/plain";
            context.Response.Write(this.getJSONResult(newsList));
            context.Response.End();
        }

        protected string getJSONResult(List<hf.Model.News> result)
        {
            JavaScriptSerializer jsSerializer = new JavaScriptSerializer(new SimpleTypeResolver());
            return jsSerializer.Serialize(result);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}